package com.leo.leetcode.s100;


/**
 *
 * @author xuexiaolei
 * @version 2017年11月21日
 */
public class T26RemoveDuplicatesfromSortedArray {
    public static int removeDuplicates(int[] nums) {
        if (nums.length < 2) return nums.length;
        int len = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] != nums[len]){
                len++;
                nums[len] = nums[i];
            }
        }
        return len+1;
    }

    public static void main(String[] args) {
        System.out.println(removeDuplicates(new int[]{}));
        System.out.println(removeDuplicates(new int[]{2}));
        System.out.println(removeDuplicates(new int[]{1,2,2,3}));
        System.out.println(removeDuplicates(new int[]{1,2,2,3,4,4,5}));
        System.out.println(removeDuplicates(new int[]{1,2,2,2,3,4,4,5}));
    }
}
